<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?><!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/public/js/html5shiv.js"></script>
    <script type="text/javascript" src="/public/js/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/public/plugins/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/public/plugins/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/public/plugins/Hui-iconfont/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/public/plugins/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/public/plugins/h-ui.admin/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/public/plugins/laydate/skins/default/laydate.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="/public/js/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>快方管理后台</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <style type="text/css">
        .date{
            width: 100px;
        }
        .label{
            font-size: 14px;
            padding: 10px;
        }
        .status_info{
            margin-bottom: 20px;
        }
        .status_info label{
            margin: 0 5px;
        }
        .status_info .title{
            font-weight: bold;
            margin-right: 10px; 
        }
    </style>
</head>
<body class="big-page">

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 门店管理 <span
        class="c-gray en">&gt;</span> 上传至第三方 <a class="btn btn-success radius r"  style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="skin-minimal mt-5">
            <form class="form1" method="get" >
                <div class="status_info"></div>
                <label for="status" class="">已经上传的平台:</label>
                <span class="select-box" style="width: 100px;">
                <select name="paltforms" class="select">
                    <?php
                    foreach($paltform as $key =>$value ){
                        ?>
                        <option  <?php if ($ptid === $value['ID']): ?> selected  <?php endif; ?>  value="<?php echo $value['ID'] ?>"><?php echo $value['TL'] ?></option>
                        <?php
                    }
                    ?>
            </select>
            </span>
            </span>
                <button class="btn btn-success radius" type="submit"><i class="Hui-iconfont"></i> 查询</button>
                <label style="margin-left: 50px" for="status" class="">请选择要上传的平台:</label>
                <?php
                foreach($paltform as $key =>$value ){
                    ?>
                    <input style="margin-left: 30px" type="checkbox" name="paltform" value="<?php echo $value['ID']?>_<?php echo $value['UNIQUE']?>_<?php echo $value['TL']?>"><?php echo $value['TL']?>
                <?php
                }
                ?>

                &emsp;
                <button class="btn btn-success radius" style="float: right" type="button" id="addOneStore" data-url="/addStore/ddBatch"> 达达上传</button>

                <button class="btn btn-success radius" style="float: right;margin-right: 20px;" type="button" id="addStore" data-url="/addStore/batch"> 批量上传</button>

                <button class="btn btn-success radius" style="float: right;margin-right: 20px" type="button" id="audit" data-url="/addStore/batchAudit"> 批量审核</button>
            </form>
        </div>
        <div class="mt-10">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive" id="dataTables">
                <thead>
                <tr class="text-c">
                    <th><input type="checkbox"> 审核 </th>
                    <th>#</th>
                    <th>药店名称</th>
                    <th>药店地址</th>
                    <th>门店状态</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </article>
</div>

<script type="text/javascript" src="/public/js/jquery.min.js"></script>
<script type="text/javascript" src="/public/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/public/plugins/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/public/plugins/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="/public/plugins/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
<script type="text/javascript" src="/public/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/public/plugins/laydate/laydate.js"></script>
<script type="text/javascript">
//达达单个上传店铺
$("#addOneStore").click(function(){
    var _this = $(this);
    
    // _this.addClass('disabled').text("正在上传");
    var url = _this.data('url');

    var id_array = [];
    $('input[name="audit"]:checked').each(function(){
        id_array.push($(this).val());
    });

    // alert(id_array);
    $.ajax({
        type: "POST",
        url: url,
        dataType:'json',
        data:{store_id:id_array},
        success: function(msg){
            if(msg.code==0){
                alert("上传成功")
                location.reload();
            }else{
                alert(msg.msg);
            }           
        }
    });
})
//批量上传店铺
$("#addStore").click(function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    _this.addClass('disabled').text("正在上传");
    var url = _this.data('url');
    var id_array = [];
    $('input[name="paltform"]:checked').each(function(){
        id_array.push($(this).val());
    });

    if(id_array.length==0){
        _this.removeClass('disabled').text("批量上传店铺");
        alert("请选择第三方平台");
        return false;
    }

    $.ajax({
        type: "POST",
        url: url,
        dataType:'json',
        data:{id:id_array},
        success: function(msg){
            alert("上传成功");
            _this.removeClass('disabled').text("批量上传店铺");
        }
    });
})

$(document).on("click",".addStore",function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    var id_array = [];
    $('input[name="paltform"]:checked').each(function(){
        id_array.push($(this).val());
    });

    if(id_array.length==0){
        _this.removeClass('disabled').text("上传");
        alert("请选择第三方平台");
        return false;
    }
    _this.addClass('disabled').text("正在上传");
    var url = _this.data('url');
    var id = _this.data('id');
    $.ajax({
        type: "POST",
        url: url,
        data:{id:id,pid:id_array},
        dataType:'json',
        success: function(msg){
            if(msg.code==200){
                alert("上传成功")
                location.reload()
            }else{
                alert(msg.msg);
            }
            _this.removeClass('disabled').text("上传");
        }
    });
})


$("#audit").click(function(){
    var _this = $(this);
    if(_this.hasClass('disabled')){
        return false;
    }
    _this.addClass('disabled').text("正在审核");
    var id_array=new Array();
    var pid_array = new Array();
    $('input[name="audit"]:checked').each(function(){
        id_array.push($(this).val());
    });
    $('input[name="paltform"]:checked').each(function(){
        pid_array.push($(this).val());
    });
    if(id_array.length==0){
        _this.removeClass('disabled').text("批量审核");
        alert("请选择要审核的药店");
        return false;
    }
    if(pid_array.length==0){
        _this.removeClass('disabled').text("批量审核");
        alert("请选择要审核的平台");
        return false;
    }
    var url = _this.data('url');
    $.ajax({
        type: "POST",
        url: url,
        dataType:'json',
        data:{id:id_array,pid:pid_array},
        success: function(msg){
            if(msg.code==200){
                alert("审核通过")
                location.reload()
            }else{
                alert('审核失败');
                _this.removeClass('disabled').text("批量审核");
            }

        }
    });
})


$('.date').on('click', function () {
    laydate({format: 'YYYY-MM-DD', istime: false})
});

var carrierStatusStyle = {
    "0" : {"title" : "未创建", "class": "label-default"},
    "1" : {"title" : "已上线", "class": "label-success"},
    "2" : {"title" : "已下线", "class": "label-danger"}
};

function initStatus(){
    $(".status_info").html("<span class='title'>平台状态 :</span>");
    for(k in carrierStatusStyle){
        var title = carrierStatusStyle[k]['title'];
        var clas = carrierStatusStyle[k]['class'];
        var html = "<label class='label " + clas + " radius'>" + title + "</label>&emsp;"
        $(".status_info").append(html);
    }
}

$(document).on("click", ".updateStatus", function(){

    var href = $(this).attr("href");
    var store_name = $(this).data("store_name");
    layer.open({
      type: 2,
      title: store_name,
      shadeClose: true,
      shade: 0.8,
      area: ['600px', '450px'],
      content: href
    }); 

    return false;
})

initStatus();
var dataTables = $('#dataTables').my_data_table({
    "fnRowCallback" :  function (sName, oData, sExpires, sPath) {

        var store_id = oData.ID;
        var store_name = oData.Caption;

        $.ajax({
            url : "/AddStore/getPtInfoByYid",
            type: "GET",
            dataType: "json",
            data: {"store_id" : store_id},
            success:function(res){
                var html = "";
                for(k in res){
                    var statuLabel = carrierStatusStyle[res[k]['PT_ZT']];
                    var labelTitle = statuLabel['title'];
                    var labelClass = statuLabel['class'];
                    var labelHref = "/AddStore/getPtStatusByYid?YID=" + store_id + "&PTID=" + res[k]['PT_ID'];

                    html += "<a data-store_name='" + store_name + "' href=" + labelHref + " title='" + labelTitle + "' class='label " + labelClass + " radius updateStatus'>"+res[k]['PT_NAME']+"</a> &emsp;";
                }
                $('td:eq(4)',sName).html(html);

            }
        })

        return sName;
    },
    columns: [
        {data: 'ID', searchable: false, orderable: false, render: function (data, type, row, meta){
                html = "<div class='checkbox'><label><input style='margin-left: 25px' value='"+data+"' name='audit' type='checkbox'></label></div>";
            return html;
        }},
        {data: 'ID'},
        {data: 'Caption'},
        {data: 'Address'},
        {data: 'status', searchable: false, orderable: false, render: function (data, type, row, meta){
            
            return "";
        }}
    ]
});

</script>
</body>
</html>
